////NTLM
//// http://davenport.sourceforge.net/ntlm.html
//// http://msdn.microsoft.com/en-us/library/windows/desktop/aa383144%28v=vs.85%29.aspx
////Base64
//// http://www.motobit.com/util/base64-decoder-encoder.asp (Tool)
//// http://lists.boost.org/Archives/boost/2010/05/166430.php
//// http://www.boost.org/doc/libs/1_46_1/libs/serialization/doc/dataflow.html
//// http://svn.chezphil.org/libpbe/trunk/include/base64.hh
//// http://svn.boost.org/svn/boost/sandbox/SOC/2009/unicode/libs/unicode/example/base64.cpp (VER)
//
//
//#include <iostream>
//#include <istream>
//#include <ostream>
//#include <string>
//#include <boost/asio.hpp>
//
//using boost::asio::ip::tcp;
//
//struct http_test
//{
//	std::string host_;
//	std::string path_;
//	std::string http_version_;
//
//	std::string proxy_address_;
//	std::string proxy_port_;
//
//	http_test()
//	{
//		host_ = "www.google.com.ar";	
//		path_ = "/";
//		http_version_ = "1.1";
//
//		proxy_address_ = "10.147.64.2";
//		proxy_port_ = "8080"; //"http"
//	}
//
//
//	int send( boost::asio::streambuf & request )
//	{
//		try
//		{
//
//			//tcp::endpoint endpoint( boost::asio::ip::address::from_string("10.147.64.2"), 8080);
//
//			boost::asio::io_service io_service;
//
//			tcp::resolver resolver(io_service);
//		
//			//tcp::resolver::query query(argv[1], "http");
//			tcp::resolver::query query( proxy_address_, proxy_port_ );
//
//			tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
//
//			tcp::socket socket(io_service);
//			boost::asio::connect(socket, endpoint_iterator);
//
//			//boost::asio::streambuf request;
//			//std::ostream request_stream(&request);
//
//
//			boost::asio::write(socket, request);
//
//			boost::asio::streambuf response;
//			boost::asio::read_until(socket, response, "\r\n");
//
//			// Check that response is OK.
//			std::istream response_stream(&response);
//			std::string http_version_response;
//			response_stream >> http_version_response;
//			unsigned int status_code;
//			response_stream >> status_code;
//			std::string status_message;
//			std::getline(response_stream, status_message);
//
//			if (!response_stream || http_version_response.substr(0, 5) != "HTTP/")
//			{
//				std::cout << "Invalid response\n";
//				return 1;
//			}
//
//			if (status_code != 200)
//			{
//				std::cout << "Response returned with status code " << status_code << "\n";
//				return 1;
//			}
//
//			boost::asio::read_until(socket, response, "\r\n\r\n");
//
//			std::string header;
//
//			while (std::getline(response_stream, header) && header != "\r")
//			{
//				std::cout << header << "\n";
//			}
//
//			std::cout << "\n";
//
//			// Write whatever content we already have to output.
//			if (response.size() > 0)
//			{
//				std::cout << &response;
//			}
//
//			// Read until EOF, writing data to output as we go.
//			boost::system::error_code error;
//			while (boost::asio::read(socket, response, boost::asio::transfer_at_least(1), error))
//			{
//				std::cout << &response;
//			}
//
//			if (error != boost::asio::error::eof)
//			{
//				throw boost::system::system_error(error);
//			}
//		}
//		catch (std::exception& e)
//		{
//			std::cout << "Exception: " << e.what() << "\n";
//		}
//	}
//
//
//	void step_old_0()
//	{
//		//request_stream << "GET " << path << " HTTP/" << http_version << "\r\n";
//		//request_stream << "Host: " << host << "\r\n";
//		//request_stream << "Accept: */*\r\n";
//		//request_stream << "Connection: close\r\n";
//		//request_stream << "\r\n";
//	}
//
//	void step1()
//	{
//		boost::asio::streambuf request;
//		std::ostream request_stream(&request);
//
//		//Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
//		//Accept-Language: es-AR
//		//User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
//		//Accept-Encoding: gzip, deflate
//		//Proxy-Connection: Keep-Alive
//		//Host: www.google.com
//		//Cookie: PREF=ID=95f129ae48a27026:U=f417ab71a4b80412:FF=0:TM=1313506129:LM=1313590779:S=MqTcUdUawVWmf4Hl; NID=51=lwbE_jekFZ13HvMAtxyibXG16M7uukjbi5w7sOOoHcL4WiQL-lSulpnYJQtSF58SOZvFrZPL4r7FSP1IXAPB75UoWCg23YpJ8hp45toWsUeYAx0Tpb-TNJf4Mkwkcscm
//	
//		request_stream << "GET " << "http://www.google.com.ar/" << " HTTP/" << http_version_ << "\r\n";
//		request_stream << "Proxy-Connection: Keep-Alive" << "\r\n";
//		request_stream << "Host: " << host_ << "\r\n";
//		request_stream << "\r\n";
//
//
//		send(request);
//
//		//Response-----------------------------------------
//		//Via: 1.1 WARGTY01
//		//Proxy-Authenticate: Negotiate
//		//Proxy-Authenticate: Kerberos
//		//Proxy-Authenticate: NTLM
//		//Connection: Keep-Alive
//		//Proxy-Connection: Keep-Alive
//		//Pragma: no-cache
//		//Cache-Control: no-cache
//		//Content-Type: text/html
//		//Content-Length: 4127
//
//
//	}
//
//	void step2()
//	{
//		boost::asio::streambuf request;
//		std::ostream request_stream(&request);
//
//
//		//GET http://www.google.com/search?hl=es&q=123&lr= HTTP/1.1
//		//Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
//		//Accept-Language: es-AR
//		//User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
//		//Accept-Encoding: gzip, deflate
//		//Proxy-Connection: Keep-Alive
//		//Cookie: PREF=ID=95f129ae48a27026:U=f417ab71a4b80412:FF=0:TM=1313506129:LM=1313590779:S=MqTcUdUawVWmf4Hl; NID=51=lwbE_jekFZ13HvMAtxyibXG16M7uukjbi5w7sOOoHcL4WiQL-lSulpnYJQtSF58SOZvFrZPL4r7FSP1IXAPB75UoWCg23YpJ8hp45toWsUeYAx0Tpb-TNJf4Mkwkcscm
//		//Proxy-Authorization: Negotiate TlRMTVNTUAABAAAAl7II4gYABgAzAAAACwALACgAAAAGAbEdAAAAD1BST0ctRlJBLTMxQ0RTLUJB
//		//Host: www.google.com
//	
//		request_stream << "GET " << "http://www.google.com.ar/" << " HTTP/" << http_version_ << "\r\n";
//		//request_stream << "Authorization: NTLM TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S\r\n";			//TODO:
//		request_stream << "Proxy-Connection: Keep-Alive" << "\r\n";
//		request_stream << "Proxy-Authorization: Negotiate TlRMTVNTUAABAAAAl7II4gYABgAzAAAACwALACgAAAAGAbEdAAAAD1BST0ctRlJBLTMxQ0RTLUJB" << "\r\n";
//		request_stream << "Host: " << host_ << "\r\n";
//		request_stream << "\r\n";
//
//
//		send(request);
//
//
//
//		//Response returned with status code 407
//		//Via: 1.1 WARGTY01
//		//Proxy-Authenticate: Negotiate TlRMTVNTUAACAAAADAAMADgAAAAVgonilcj4Ud4XZCoAAAAAAAAAAJoAmgBEAAAABgGxHQAAAA9DAEQAUwAtAEIAQQACAAwAQwBEAFMALQBCAE
//		//EAAQAQAFcAQQBSAEcAVABZADAAMQAEABgAYwBkAHMALQBiAGEALgBsAG8AYwBhAGwAAwAqAFcAQQBSAEcAVABZADAAMQAuAGMAZABzAC0AYgBhAC4AbABvAGMAYQBsAAUAGABjAGQAcw
//		//AtAGIAYQAuAGwAbwBjAGEAbAAHAAgAx6Se+fGBzAEAAAAA
//		//Connection: Keep-Alive
//		//Proxy-Connection: Keep-Alive
//		//Pragma: no-cache
//		//Cache-Control: no-cache
//		//Content-Type: text/html
//		//Content-Length: 0
//
//
//
//
//
//
//
//
//
//
//
//
//
//	}
//
//	void step3()
//	{
//		boost::asio::streambuf request;
//		std::ostream request_stream(&request);
//
//		//GET http://www.google.com/search?hl=es&q=123&lr= HTTP/1.1
//		//Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
//		//Accept-Language: es-AR
//		//User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2)
//		//Accept-Encoding: gzip, deflate
//		//Proxy-Connection: Keep-Alive
//		//Cookie: PREF=ID=95f129ae48a27026:U=f417ab71a4b80412:FF=0:TM=1313506129:LM=1313590779:S=MqTcUdUawVWmf4Hl; NID=51=lwbE_jekFZ13HvMAtxyibXG16M7uukjbi5w7sOOoHcL4WiQL-lSulpnYJQtSF58SOZvFrZPL4r7FSP1IXAPB75UoWCg23YpJ8hp45toWsUeYAx0Tpb-TNJf4Mkwkcscm
//		//Host: www.google.com
//		//Proxy-Authorization: Negotiate TlRMTVNTUAADAAAAGAAYAKIAAAA+AT4BugAAAAwADABYAAAAKAAoAGQAAAAWABYAjAAAABAAEAD4AQAAFYKI4gYBsR0AAAAPy72xJaOjXE2Rr5LIM+1luUMARABTAC0AQgBBAEYAZQByAG4AYQBuAGQAbwAuAFAAZQBsAGwAaQBjAGMAaQBvAG4AaQBQAFIATwBHAC0ARgBSAEEALQAzADEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKRmooE1Q3W7tOvV84UALuQEBAAAAAAAAF3tYjtyBzAG104wK5Ak3vQAAAAACAAwAQwBEAFMALQBCAEEAAQAQAFcAQQBSAEcAVABZADAAMQAEABgAYwBkAHMALQBiAGEALgBsAG8AYwBhAGwAAwAqAFcAQQBSAEcAVABZADAAMQAuAGMAZABzAC0AYgBhAC4AbABvAGMAYQBsAAUAGABjAGQAcwAtAGIAYQAuAGwAbwBjAGEAbAAHAAgAF3tYjtyBzAEGAAQAAgAAAAgAMAAwAAAAAAAAAAAAAAAAMAAAMuDHhWGrtMlumrjuhPLFjWz3nL//clg/Ac3TAlb47hkKABAAAAAAAAAAAAAAAAAAAAAAAAkAHABIAFQAVABQAC8AMQAyADcALgAwAC4AMAAuADEAAAAAAAAAAAAAAAAAtEBJtuOZ/iNIPu1YYzoorQ==
//
//
//		request_stream << "GET " << "http://www.google.com.ar/" << " HTTP/" << http_version_ << "\r\n";
//		//request_stream << "Authorization: NTLM TlRMTVNTUAABAAAAA7IAAAoACgApAAAACQAJACAAAABMSUdIVENJVFlVUlNBLU1JTk9S\r\n";			//TODO:
//		request_stream << "Proxy-Connection: Keep-Alive" << "\r\n";
//		request_stream << "Proxy-Authorization: Negotiate TlRMTVNTUAADAAAAGAAYAKIAAAA+AT4BugAAAAwADABYAAAAKAAoAGQAAAAWABYAjAAAABAAEAD4AQAAFYKI4gYBsR0AAAAPy72xJaOjXE2Rr5LIM+1luUMARABTAC0AQgBBAEYAZQByAG4AYQBuAGQAbwAuAFAAZQBsAGwAaQBjAGMAaQBvAG4AaQBQAFIATwBHAC0ARgBSAEEALQAzADEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKRmooE1Q3W7tOvV84UALuQEBAAAAAAAAF3tYjtyBzAG104wK5Ak3vQAAAAACAAwAQwBEAFMALQBCAEEAAQAQAFcAQQBSAEcAVABZADAAMQAEABgAYwBkAHMALQBiAGEALgBsAG8AYwBhAGwAAwAqAFcAQQBSAEcAVABZADAAMQAuAGMAZABzAC0AYgBhAC4AbABvAGMAYQBsAAUAGABjAGQAcwAtAGIAYQAuAGwAbwBjAGEAbAAHAAgAF3tYjtyBzAEGAAQAAgAAAAgAMAAwAAAAAAAAAAAAAAAAMAAAMuDHhWGrtMlumrjuhPLFjWz3nL//clg/Ac3TAlb47hkKABAAAAAAAAAAAAAAAAAAAAAAAAkAHABIAFQAVABQAC8AMQAyADcALgAwAC4AMAAuADEAAAAAAAAAAAAAAAAAtEBJtuOZ/iNIPu1YYzoorQ==" << "\r\n";
//		request_stream << "Host: " << host_ << "\r\n";
//		request_stream << "\r\n";
//
//
//		send(request);
//	}
//
//};
//
//int main(int argc, char* argv[])
//{
//	http_test test;
//	test.step1();
//	test.step2();
//	test.step3();
//
//	return 0;
//}
